window.KONFIGURATOR_IMGPATH_POPUP = '/{$IMGPATH_POPUP}';
window.KONFIGURATOR_IMGPATH_THMB = '/{$IMGPATH_THMB}';

{literal}
$(document).ready(function() {
	$('img.ask').popuphelp();

	$('input.button_popup_layer').popuplayer();
 	$('.container_popup_layer .btn_close').click(function() {
 		$('.container_popup_layer').fadeOut(300);
		return false;
	});
	
	if ($('#konfigurator_options_list').length > 0) KONFIGURATOR_group_list();
	
});
{/literal}


function KONFIGURATOR_group_list() {
	var idx = 0;
	var $container = $('#konfigurator_options_list');

	if ($container.children('div').length == 0) {
		$('a[href=#tab_konfigurator]').parents('li').hide();
		$('#tab_konfigurator').hide();
	}
	
	else {
		var $divs = $container.children('div [class^=gallery]');
		if ($divs.length > 0) {
			$container.prepend('<div class="gallery-list-group"><div class="gallery-list-name">Optionen</div></div>');
			for(idx=0; idx < $divs.length; idx++) {
				$container.children('div.gallery-list-group').append($divs[idx]);
			}
		}

		$divs = $container.children('div [class^=info]');
		if ($divs.length > 0) {
			for(idx=0; idx < $divs.length; idx++) {
				$container.parent().children('td.info-list-group').append($divs[idx]);
			}
		}
		else
			$container.parent().children('td.info-list-group').hide();
	}
	
}

{if $FORM_ACTION == true}
{literal}

$(document).ready(function() {
  $('#tab-konfigurator ul.ad-thumb-list li[rel!=konfigurator_option]').remove();
	$('#cart_quantity input.konfigurator').change(function() {
		$(this).parents('div[tmpl]').prev().removeClass('submit_error');
		xajax_getNewPrice($("#cart_quantity").serialize(true));
	});
	
 	$('#cart_quantity').submit(KONFIGURATOR_evalValues);
	$('#box-error div.box-error_button').click(function() { $('#box-error').hide(); $('#mask_popup').hide(); });	
});

function KONFIGURATOR_clickOnThmb() {
	var img = $(this).find('a').attr('href');
	$.prettyPhoto.open(img);
	return false;
}

KONFIGURATOR_objects = [];
KONFIGURATOR_evalValues = function() { 	
	$D('check .. ' + KONFIGURATOR_objects);
	var errMsg = [];
	
	$.each(KONFIGURATOR_objects, function(){
		if ($.isFunction(window['KONFIGURATOR_'+this].evalValue)) {
			option_status = window['KONFIGURATOR_'+this].evalValue();
			
			if (option_status.status == 'failed') {
				$('div[tmpl='+this+']').prev('div').addClass('submit_error');
				errMsg.push(option_status.msg);
			}
			else
				$('div[tmpl='+this+']').prev('div').removeClass('submit_error');
		
		}
	});
	
	if ( errMsg.length > 0 ) {
		$('#mask_popup').show();
		$('#box-error div.box-error_text').html('<span>* ' + errMsg.join('<br/>* ') + '</span>')
		$('#box-error').center();
		$('#box-error').show();
	}
	else
		$('#box-error').hide();


	return (errMsg.length == 0);
}

{/literal}
{/if}